<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>活动-分享设置</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="./css/business.css">
</head>
<body>
<div id="uniocn" class="layui-layout layui-layout-admin">
    <div class="financeTitle">
        <button class="layui-btn layui-btn-ms">分享设置</button>
    </div>
    <div class="activityBox">
        <p class="activityTitle">分享设置</p>
        <form action="##" class="layui-form" style="box-sizing: border-box;margin: 15px">
            <div class="layui-form-item">
                <label class="layui-form-label">分享图片</label>
                <div class="layui-input-inline" style="margin-right: 0 ;width: 45%;">
                    <input  class="layui-input">
                    <p class="tip">图片建议为正方形,如果不选择,默认为商品缩略图</p>

                    <div class="layui-upload-list">
                        <img class="layui-upload-img shopImg" id="demo1">
                        <p id="demoText"></p>
                    </div>
                </div>
                <button id="test1" class="layui-btn layui-btn-primary">选择图片</button>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分享标题</label>
                <div class="layui-input-inline" style="width: 45%;">
                    <input type="text" class="layui-input">
                    <p class="tip">如果不填写,默认为商品名称</p>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分享描述</label>
                <div class="layui-input-inline" style="width:45%;">
                    <input type="text" class="layui-input">
                    <p class="tip">如果不填写,默认为商品描述</p>
                </div>
            </div>
            <div class="layui-form-item" style="margin-top: 20px">
                <div class="layui-input-block" style="width:45%;">
                    <button class="layui-btn layui">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script src="layui/layui.js"></script>\
<script src="js/jquery-3.2.1.min.js"></script>
<script>
    layui.use(['form','upload'],function () {
        var form = layui.form;
        var upload = layui.upload;
        //执行实例
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</html>